function fill_val(obj, ele_id, types = false, job_numbers = false) {
    document.getElementById("new_models").style.display = "table";
    var id = ele_id;
    sessionStorage.clear();
    document.getElementById("an_branch").style.color = "#01aaed";   // 按部门
    document.getElementById("an_role").style.color = "#0b0b0b";     // 按角色
    document.getElementById("an_staff").style.color = "#0b0b0b";     // 按人员
    document.getElementById("all_select_checkbox").checked = false; // 右侧弹框
    var check_box_list = document.getElementsByClassName("check_box");
    document.getElementById("search_button").setAttribute("onclick", "search_data()");
    document.getElementById("an_branch").setAttribute("onclick", "change_left_val(this.id)");    // 按部门
    document.getElementById("an_role").setAttribute("onclick", "change_left_val(this.id)");      // 按角色
    document.getElementById("an_staff").setAttribute("onclick", "change_left_val(this.id)");     // 按人员
    for (var t = 0; t < check_box_list.length; t++) {
        document.getElementById(check_box_list[t].id).checked = false;
    }
    document.getElementById("checked-label").innerHTML = "";

    document.getElementById("model-affirm").setAttribute("onclick", "summit_val1('" + ele_id + "')");
    document.getElementById("model_title").innerText = "选择审批人";

    deltr1();
    document.getElementById("img-display1").style.display = "inline-block";
    if (window.branch_list) {
        var branch_list = window.branch_list;
        var department_list = document.getElementById("department_list");
        department_list.innerHTML = "";
        var ul_tag = document.createElement("ul");
        ul_tag.style.fontSize = "0";
        ul_tag.style.margin = "0";
        ul_tag.style.padding = "0";
        for (var i = 0; i < branch_list.length; i++) {
            var li_tag = document.createElement("li");
            li_tag.style.fontSize = "14px";
            li_tag.style.margin = "0";
            li_tag.style.padding = "0";
            li_tag.innerHTML = branch_list[i];
            li_tag.setAttribute("id", branch_list[i]);
            li_tag.setAttribute("onclick", "choice_peopel('" + branch_list[i] + "', " + "this.id" + ")");
            li_tag.className = "li-class";
            ul_tag.appendChild(li_tag);
            department_list.appendChild(ul_tag);
        }
    } else {
        var xhr = new XMLHttpRequest();
        var local_host = window.location.host;          // 获取当前IP
        xhr.open('post', "/technological/delegation", true);
        xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
        xhr.send();
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    var JsonDate = JSON.parse(xhr.responseText);
                    window.personnel_list = JsonDate["data"];
                    window.emp_info_dict = JsonDate["emp_info_dict"];       // 医院所有人员名称、工号、部门
                    window.people_dict = JsonDate["people_dict"];
                    window.people_dict_new = JsonDate["people_dict_new"];
                    window.branch_list = JsonDate["branch_list"];
                    window.function_list = JsonDate["function_list"];
                    var department_list = document.getElementById("department_list");
                    department_list.innerHTML = "";
                    var ul_tag = document.createElement("ul");
                    ul_tag.style.fontSize = "0";
                    ul_tag.style.margin = "0";
                    ul_tag.style.padding = "0";
                    for (var i = 0; i < JsonDate["branch_list"].length; i++) {
                        var li_tag = document.createElement("li");
                        li_tag.style.fontSize = "14px";
                        li_tag.style.margin = "0";
                        li_tag.style.padding = "0";
                        li_tag.innerHTML = JsonDate["branch_list"][i];
                        li_tag.setAttribute("id", JsonDate["branch_list"][i]);
                        li_tag.setAttribute("onclick", "choice_peopel('" + JsonDate["branch_list"][i] + "', " + "this.id" + ")");
                        li_tag.className = "li-class";
                        ul_tag.appendChild(li_tag);
                        department_list.appendChild(ul_tag);
                    }
                }
            }
        }
    }
}

function choice_peopel(choice_key, chose_id) {
    var data_str = sessionStorage.getItem(choice_key);
    var data_list = [];
    if (data_str) {
        data_list = data_str.split(",")
    }
    var emp_info_dict = window.emp_info_dict;
    document.getElementById("img-display1").style.display = "none";
    var t_table = document.getElementById("t_table2");
    if (document.getElementsByClassName("li-class add_background").length > 0) {
        var old_tag_id = document.getElementsByClassName("li-class add_background")[0].id;
        document.getElementById(old_tag_id).className = "li-class";
    }
    document.getElementById(choice_key).className = "li-class add_background";
    deltr1();
    document.getElementById("all_select_checkbox").checked = false;

    an_branch = document.getElementById(choice_key).innerText

    var tttt = 0;
    if (data_list) {
        if (data_list[0] === "all") {
            document.getElementById("all_select_checkbox").checked = true;
            tttt = 1
        }
    }
    for (var III = tttt; III < data_list.length; III++) {
        document.getElementById(data_list[III].trim()).checked = true;
    }
}

function choice_peopel_3(choice_key, chose_id) {
    var data_str = sessionStorage.getItem(choice_key);
    var data_list = [];
    if (data_str) {
        data_list = data_str.split(",")
    }
    var emp_info_dict = window.emp_info_dict;
    document.getElementById("img-display1").style.display = "none";
    var t_table = document.getElementById("t_table2");
    if (document.getElementsByClassName("li-class add_background").length > 0) {
        var old_tag_id = document.getElementsByClassName("li-class add_background")[0].id;
        document.getElementById(old_tag_id).className = "li-class";
    }
    document.getElementById(choice_key).className = "li-class add_background";
    deltr1();
    document.getElementById("all_select_checkbox").checked = false;
    document.getElementById("all_select_checkbox").setAttribute("onclick", "check_all_select('" + choice_key + "', '" + chose_id + "')");

    for (var i = 0; i < emp_info_dict[choice_key].length; i++) {
        var elm = emp_info_dict[choice_key]
        var tr = document.createElement("tr");
        var td = document.createElement("td");
        var td1 = document.createElement("td");
        var td2 = document.createElement("td");
        var td3 = document.createElement("td");
        td.innerHTML = "<input id='" + elm[i].real_name + "(" + elm[i].job_number + ')' + "' class='check_box' type=\"checkbox\" onclick='choice_consignor(this.id, \"" + chose_id + "\"" + ", \"" + choice_key + "\")'>";
        td.style.textAlign = "center";
        td1.innerHTML = i + 1;
        td1.style.textAlign = "center";
        td2.innerHTML = elm[i].real_name;
        td2.title = elm[i].real_name;
        td2.style.textAlign = "center";
        td3.innerHTML = elm[i].job_number;
        td3.title = elm[i].job_number;
        td3.style.textAlign = "center";
        tr.appendChild(td);
        tr.appendChild(td1);
        tr.appendChild(td2);
        tr.appendChild(td3);
        t_table.appendChild(tr);
    }

    var tttt = 0;
    if (data_list) {
        if (data_list[0] === "all") {
            document.getElementById("all_select_checkbox").checked = true;
            tttt = 1
        }
    }
    for (var III = tttt; III < data_list.length; III++) {
        document.getElementById(data_list[III].trim()).checked = true;
    }
}

function close_page() {
    document.getElementById('new_models_1').style.display = 'none'
}

// 创建右侧选择人员列表   按角色
function choice_peopel_1(choice_key, chose_id) {
    var data_str = sessionStorage.getItem(choice_key);      // choice_key为分管领导、科室负责人   id 为0、1
    var data_list = [];
    if (data_str) {
        data_list = data_str.split(",")
    }
    document.getElementById("img-display1").style.display = "none";
    if (document.getElementsByClassName("li-class add_background").length > 0) {
        var old_tag_id = document.getElementsByClassName("li-class add_background")[0].id;
        document.getElementById(old_tag_id).className = "li-class";
    }
    document.getElementById(choice_key).className = "li-class add_background";
    deltr1();
    document.getElementById("all_select_checkbox").checked = false;
    var tttt = 0;
    if (data_list) {
        if (data_list[0] === "all") {
            document.getElementById("all_select_checkbox").checked = true;
            tttt = 1
        }
    }
    for (var III = tttt; III < data_list.length; III++) {
        document.getElementById(data_list[III].trim()).checked = true;
    }
    an_role = document.getElementById(choice_key).innerText
}

// 创建右侧选择人员列表
function choice_peopel_2(choice_key, chose_id) {
    var data_str = sessionStorage.getItem(choice_key);
    var data_list = [];
    if (data_str) {
        data_list = data_str.split(",")
    }

    var people_dict_new = window.function_list;
    document.getElementById("img-display1").style.display = "none";
    var t_table = document.getElementById("t_table2");
    if (document.getElementsByClassName("li-class add_background").length > 0) {
        var old_tag_id = document.getElementsByClassName("li-class add_background")[0].id;
        document.getElementById(old_tag_id).className = "li-class";
    }
    document.getElementById(choice_key).className = "li-class add_background";
    deltr1();
    document.getElementById("all_select_checkbox").checked = false;
    document.getElementById("all_select_checkbox").setAttribute("onclick", "check_all_select('" + choice_key + "', 'executor2')")
    for (var i = 0; i < people_dict_new[choice_key].length; i++) {
        var elm = people_dict_new[choice_key];
        var tr = document.createElement("tr");
        var td = document.createElement("td");
        var td1 = document.createElement("td");
        var td2 = document.createElement("td");
        var td3 = document.createElement("td");
        td.innerHTML = "<input id='" + elm[i].real_name + '(' + elm[i].job_number + ')' + "' class='check_box' type=\"checkbox\" onclick='choice_consignor(this.id, \"" + chose_id + "\"" + ", \"" + choice_key + "\")'>";
        td.style.textAlign = "center";
        td1.innerHTML = i + 1;
        td1.style.textAlign = "center";
        td2.innerHTML = elm[i].real_name;
        td2.title = elm[i].real_name;
        td2.style.textAlign = "center";
        td3.innerHTML = elm[i].job_number;
        td3.title = elm[i].job_number;
        td3.style.textAlign = "center";
        tr.appendChild(td);
        tr.appendChild(td1);
        tr.appendChild(td2);
        tr.appendChild(td3);
        t_table.appendChild(tr);
    }
    var tttt = 0;
    if (data_list) {
        if (data_list[0] === "all") {
            document.getElementById("all_select_checkbox").checked = true;
            tttt = 1
        }
    }
    for (var III = tttt; III < data_list.length; III++) {
        document.getElementById(data_list[III].trim()).checked = true;
    }
}

function create_table1(json_data) {
    var t_table = document.getElementById("t_table1");
    var menu_name = "";
    var mwnu_num = 0;
    var menu_num = 1;
    for (var i = 0; i < json_data.length; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");
        var td1 = document.createElement("td");
        var td2 = document.createElement("td");
        var td3 = document.createElement("td");
        var td4 = document.createElement("td");
        if (json_data[i]["menu"] !== menu_name) {
            menu_name = json_data[i]["menu"];
            mwnu_num += 1;
            menu_num = 1;
            var tr_1 = document.createElement("tr");
            var td_1 = document.createElement("td");
            var td1_1 = document.createElement("td");
            var td2_1 = document.createElement("td");
            var td3_1 = document.createElement("td");
            td_1.innerHTML = '<a href="#" onclick="menu_contraction(\'' + "0" + String(mwnu_num) + '\', \'' + "0" + String(mwnu_num) + '\')"><i id="' + "0" + String(mwnu_num) + '" class="iconfont icon-sanjiaoyou"></i> ' + menu_name + '</a>';
            td_1.style.paddingLeft = "1%";
            td1_1.innerHTML = "0" + String(mwnu_num);
            td1_1.style.paddingLeft = "3.5%";
            td2_1.innerHTML = "有效";
            td2_1.style.textAlign = "center";
            td3_1.innerHTML = '<p onclick="padding_data(\'' + json_data[i]["menu"] + '\')"><i  class="iconfont icon-zhucetianjiahaoyou"></i> 添加</p>';
            td3_1.style.textAlign = "center";
            td3_1.style.color = "#0c6fd9";
            td3_1.style.cursor = "pointer";
            tr_1.appendChild(td_1);
            tr_1.appendChild(td1_1);
            tr_1.appendChild(td2_1);
            tr_1.appendChild(td3_1);
            t_table.appendChild(tr_1);


            tr.className = "0" + String(mwnu_num);
            tr.style.display = "none";
            td.innerHTML = '<a href="#">' + json_data[i]["bill"] + '</a>';
            td.style.paddingLeft = "3%";
            td1.innerHTML = "0" + String(mwnu_num) + "-" + String(menu_num);
            td1.style.paddingLeft = "3.5%";
            td2.innerHTML = "有效";
            td2.style.textAlign = "center";
            td3.innerHTML = '/';
            td3.style.textAlign = "center";
            td3.style.color = "#0c6fd9";
            td3.style.cursor = "pointer";
            menu_num += 1
        } else {
            tr.className = "0" + String(mwnu_num);
            tr.style.display = "none";
            td.innerHTML = '<a href="#">' + json_data[i]["bill"] + '</a>';
            td.style.paddingLeft = "3%";
            td1.innerHTML = "0" + String(mwnu_num) + "-" + String(menu_num);
            td1.style.paddingLeft = "3.5%";
            td2.innerHTML = "有效";
            td2.style.textAlign = "center";
            td3.innerHTML = '/';
            td3.style.textAlign = "center";
            td3.style.color = "#0c6fd9";
            td3.style.cursor = "pointer";
            menu_num += 1
        }

        tr.appendChild(td);
        tr.appendChild(td1);
        tr.appendChild(td2);
        tr.appendChild(td3);
        t_table.appendChild(tr);
    }
}

// 删除列表
function deltr() {
    var tb = document.getElementById('t_table');
    var rowNum = tb.rows.length;
    for (i = 0; i < rowNum; i++) {
        tb.deleteRow(i);
        rowNum = rowNum - 1;
        i = i - 1;
    }
}

// 删除列表
function deltr1() {
    var tb = document.getElementById('t_table2');
    var rowNum = tb.rows.length;
    for (i = 0; i < rowNum; i++) {
        tb.deleteRow(i);
        rowNum = rowNum - 1;
        i = i - 1;
    }
}

// 删除列表
function deltr2() {
    var tb = document.getElementById('t_table1');
    var rowNum = tb.rows.length;
    for (i = 0; i < rowNum; i++) {
        tb.deleteRow(i);
        rowNum = rowNum - 1;
        i = i - 1;
    }
}

// 选择委托人
function choice_consignor(ele_id, chose_id, choice_key) {
    var check_tag_list = document.getElementsByClassName("check_box");
    for (var t = 0; t < check_tag_list.length; t++) {
        if (check_tag_list[t].id !== ele_id) {
            check_tag_list[t].checked = false
        }
    }

    chose_id = 'executor2';
    if (chose_id === "executor2" || chose_id === "executor4") {
        var dataStr = sessionStorage.getItem(choice_key);
        var dataList = [];
        if (dataStr) {
            sessionStorage.setItem(choice_key, dataStr + ", " + ele_id)
        } else {
            sessionStorage.setItem(choice_key, ele_id)
        }

        if (chose_id === "executor2") {
            var tag_id = "executor_str";
        } else {
            tag_id = "executor_str1";
        }
        var executor_str = document.getElementById(tag_id);
        if (executor_str) {
            if (document.getElementById(ele_id).checked) {
                if (executor_str.innerText.trim()) {
                    document.getElementById(tag_id).innerHTML = executor_str.innerText + ", " + ele_id;
                } else {
                    document.getElementById(tag_id).innerHTML = ele_id;
                }
            } else {
                var str_push = [];
                var executor_list = executor_str.innerText.split(", ");
                for (var kl = 0; kl < executor_list.length; kl++) {
                    if (executor_list[kl] !== ele_id) {
                        str_push.push(executor_list[kl])
                    }
                }
                document.getElementById(tag_id).innerHTML = str_push.join(", ")
            }
        } else {
            document.getElementById("checked-label").innerHTML = "<span id='" + tag_id + "' style='margin-left: 1%;width: 100%;'>" + ele_id + "</span>";
        }
    } else {
        check_more_one_not(ele_id);
        document.getElementById("checked-label").innerHTML = "<span id='" + tag_id + "' style='margin-left: 1%;'>" + ele_id + "</span>";
    }

}

// 复选框全选
function check_all_select(choice_key, chose_id) {
    var select_check = document.getElementById("all_select_checkbox").checked;
    var all_check_box = document.getElementsByClassName("check_box");
    chose_id = 'executor2'
    if (chose_id === "executor2") {
        var tag_id = "executor_str";
    } else {
        tag_id = "executor_str1";
    }

    var executor_list = [];
    var executor_str = document.getElementById(tag_id);
    if (executor_str) {
        if (executor_str.innerText.trim()) {
            executor_list = executor_str.innerText.split(", ")
        }
    }

    var new_check_val_list = [];
    var check_val_list = [];
    for (var HH = 0; HH < all_check_box.length; HH++) {
        all_check_box[HH].checked = true;
        check_val_list.push(all_check_box[HH].id);
        if (executor_list.lastIndexOf(all_check_box[HH].id) === -1) {
            new_check_val_list.push(all_check_box[HH].id)
        }
    }

    if (select_check) {
        if (chose_id === "executor2" || chose_id === "executor4") {

            if (executor_str) {
                if (executor_str.innerText.trim()) {
                    document.getElementById(tag_id).innerHTML = executor_str.innerText + ", " + new_check_val_list.join(", ");
                } else {
                    document.getElementById(tag_id).innerHTML = new_check_val_list.join(", ");
                }

            } else {
                document.getElementById("checked-label").innerHTML = "<span id='" + tag_id + "' style='margin-left: 1%;width: 100%;'>" + check_val_list.join(", ") + "</span>";
            }
            sessionStorage.setItem(choice_key, "all" + ", " + check_val_list.join(", "))
        } else {
            alert("该节点不能多选！");
            document.getElementById("all_select_checkbox").checked = false;
        }
    } else {
        sessionStorage.removeItem(choice_key);
        check_val_list = [];
        for (var II = 0; II < all_check_box.length; II++) {
            all_check_box[II].checked = false;
            check_val_list.push(all_check_box[II].id);
        }
        var old_check_val = document.getElementById(tag_id).innerHTML.split(", ");
        for (var TB = 0; TB < check_val_list.length; TB++) {
            removeByValue(old_check_val, check_val_list[TB])
        }

        document.getElementById(tag_id).innerHTML = old_check_val.join(", ");
    }
};

function removeByValue(arr, val) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] === val) {
            arr.splice(i, 1);
            break;
        }
    }
};

// checkBox不允许多选
function check_more_one_not(ele_id) {
    var check_box_list = document.getElementsByClassName("check_box");
    for (var i = 0; i < check_box_list.length; i++) {
        if (String(check_box_list[i].id) !== String(ele_id)) {
            document.getElementById(check_box_list[i].id).checked = false;
        } else {
            document.getElementById(check_box_list[i].id).checked = true;
        }
    }
}

// 选择执行人
function summit_val(id) {
    var executor111 = '';
    var checked_label = document.getElementById("checked-label");
    for (var j = 0; j < checked_label.children.length; j++) {
        executor111 = executor111 + checked_label.children[j].innerText.trim() + ", ";
    }
    document.getElementById("close-model").click();
    var executor = executor111.slice(0, -2);
    var page = document.getElementsByClassName("active")[0].innerText;
    document.getElementById("loading").style.display = "inline-block";
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP

    xhr.open('get', "/personal-center/bill_group_view?page=" + String(page) + '&id=' + String(id) + '&executor=' + String(executor));
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
    xhr.send();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                create_table(JsonDate["count"], JsonDate["bill_groups"]);
                create_table1(JsonDate["bill_groups"]);
                pagenum(JsonDate["count"], page);
            }
        }
    };

}

(function ($) {
    $.fn.MySelect = function () {
        this.each(function () {
            var $box = $(this);
            var $input = $box.find("input.my-select-input");  //输入框
            var $list = $input.next();                          //ul装扮成下拉框
            var inputHeight = $input.outerHeight();   //计算input输入框的高度和宽度，方便定位ul和设置ul及包裹元素的宽度
            //var inputWidth=$input.innerWidth();
            $list.css({"top": (inputHeight)});
            //$box.width($input.outerWidth());

            $input.focus(function () {   //输入框获得焦点后，显示下拉选择ul
                var $nextUl = $(this).next();
                if ($nextUl.children().length > 0) {
                    $(this).next().show();
                }
            }).bind('input propertychange', function () {  //绑定监测输入框的输入值更改
                var $this = $(this);
                $this.attr("data-id", "");
                var curText = $this.val();
                var $nextUl = $(this).next();
                if ($nextUl.children().length > 0) {
                    $nextUl.find("li").removeClass("choosed");
                    $nextUl.find("li").each(function (i, item) {
                        var txt = $(item).text();
                        if (txt === curText) {
                            var v = $(item).attr("data-value");
                            $this.attr("data-id", v);
                            $(item).addClass("choosed");
                        }
                    });
                }
            });
            $list.off('click', 'li').on('click', 'li', function (e) {
                var $this = $(this);
                var value = $this.attr("data-value") || '';
                $input.val($this.text()).attr("data-id", value);
                $this.addClass("choosed").siblings().removeClass("choosed");
                $this.parent().hide();
            });
        });

        $(document).click(function (e) {  //点击.my-select-box范围外时隐藏ul下拉框
            var target = e.target;
            var $target = $(target);
            var $parent = $target.closest('.my-select-box');
            if ($parent.length < 1) {  //说明不是.my-select-box范围内点击，将ul隐藏
                $(".my-select-list").hide();
            } else if ($parent.length == 1) {  //如果存在多个my-select-box的情况，将其余的非这项以外的都隐藏
                var $ul = $parent.find(".my-select-list");
                var flag = $ul.is(":hidden");
                $(".my-select-list").hide();
                if (!flag) $ul.show();
            }
        });
        return this;
    }
})(jQuery);

$(".my-select-box").MySelect();

function summit_val1(obj) {
    if (window.id === 'an_role') {
        document.getElementById(obj).innerHTML = an_role
        document.getElementById(obj).dataset.id = 'role'
    } else if (window.id === 'an_branch') {
        document.getElementById(obj).innerHTML = an_branch
        document.getElementById(obj).dataset.id = 'branch'
    } else if (window.id === 'an_staff') {
        var check_box_li = document.getElementsByClassName("check_box");
        for (var i = 0; i < check_box_li.length; i++) {
            if (check_box_li[i].checked) {
                document.getElementById(obj).innerHTML = check_box_li[i].id
                document.getElementById(obj).dataset.id = 'staff'
            }
        }
    } else {
        document.getElementById(obj).innerHTML = an_branch
        document.getElementById(obj).dataset.id = 'branch'
    }
    window.id = 'an_branch'
    document.getElementById("new_models").style.display = "none";
    document.getElementById(obj).style.color = 'black'
}

// 加载分页条
function pagenum(dataTotals = 1, page = 1) {
    new myPagination({
        id: 'pagination',
        curPage: page, //初始页码
        pageAmount: 20,  //每页多少条
        dataTotal: dataTotals, //总共多少条数据
        pageTotal: Math.ceil(parseInt(dataTotals, 10) / 20), //总页数
        pageSize: 5, //可选,分页个数
        showPageTotalFlag: true, //是否显示数据统计
        showSkipInputFlag: true, //是否支持跳转
        getPage: function (page) {
            // var query_type = document.getElementById("query_type").value;
            // var query_value = document.getElementById("query_value").value;
            initialize(page);
        }
    });
}

function menu_contraction(contraction_num, Id_e) {
    var Issue_approval = document.getElementsByClassName(contraction_num);
    if (document.getElementById(Id_e).className === "iconfont icon-sanjiaoyou") {
        document.getElementById(Id_e).className = "iconfont icon-sanjiaoxia";
    } else {
        document.getElementById(Id_e).className = "iconfont icon-sanjiaoyou"
    }

    if (Issue_approval.length !== 0 && Issue_approval[0].style.display === "table-row") {
        for (var i = 0; i < Issue_approval.length; i++) {
            Issue_approval[i].style.display = "none";
        }
    } else {
        for (var j = 0; j < Issue_approval.length; j++) {
            Issue_approval[j].style.display = "table-row";
        }
    }

}

function change_left_val(ele_id) {
    window.id = ele_id
    if (ele_id === "an_role") {                                             // 按角色
        document.getElementById("an_branch").style.color = "#0b0b0b";
        document.getElementById("an_staff").style.color = "#0b0b0b";
        document.getElementById(ele_id).style.color = "#01aaed";
        document.getElementById('right_role_li').style.display = 'none'
        document.getElementById('department_list').style.display = 'inline-block'
        deltr1();
        document.getElementById("img-display1").style.display = "inline-block";
        document.getElementById("department_list").innerHTML = "";
        var new_branch_list = ["分管领导:FGLD", "科室负责人:KSFZR"];
        var new_department_list = document.getElementById("department_list");
        var new_ul_tag = document.createElement("ul");new_ul_tag.style.fontSize = "0";new_ul_tag.style.margin = "0";new_ul_tag.style.padding = "0";
        for (var EF = 0; EF < new_branch_list.length; EF++) {
            var new_li_tag = document.createElement("li");new_li_tag.style.fontSize = "14px";new_li_tag.style.margin = "0";new_li_tag.style.padding = "0";new_li_tag.style.paddingLeft = "5%";new_li_tag.innerHTML = new_branch_list[EF].split(":")[0];new_li_tag.setAttribute("onclick", "choice_peopel_1('" + new_branch_list[EF].split(":")[1] + "', " + "this.id" + ")");new_li_tag.setAttribute("id", new_branch_list[EF].split(":")[1]);new_li_tag.className = "li-class";new_ul_tag.appendChild(new_li_tag);
            new_department_list.appendChild(new_ul_tag);
        }
    } else if (ele_id === 'an_staff') {     // 按人员
        document.getElementById("an_branch").style.color = "#0b0b0b";
        document.getElementById("an_role").style.color = "#0b0b0b";
        document.getElementById(ele_id).style.color = "#01aaed";
        document.getElementById('right_role_li').style.display = 'inline-block';
        document.getElementById('department_list').style.display = 'inline-block';
        deltr1();
        document.getElementById("img-display1").style.display = "inline-block";
        document.getElementById("department_list").innerHTML = "";
        var department_list_1 = document.getElementById("department_list");department_list_1.innerHTML = "";
        var ul_tag_1 = document.createElement("ul");ul_tag_1.style.fontSize = "0";ul_tag_1.style.margin = "0";ul_tag_1.style.padding = "0";
        var function_list = window.branch_list;

        for (var i = 0; i < function_list.length; i++) {
            var new_li_1 = document.createElement("li");new_li_1.style.fontSize = "14px";new_li_1.style.margin = "0";new_li_1.style.padding = "0";new_li_1.innerHTML = function_list[i];new_li_1.setAttribute("id", function_list[i]);new_li_1.setAttribute("onclick", "choice_peopel_3('" + function_list[i] + "', " + "this.id" + ")");new_li_1.className = "li-class";
            ul_tag_1.appendChild(new_li_1);department_list_1.appendChild(ul_tag_1);
        }
    } else {           // 按部门
        document.getElementById("an_role").style.color = "#0b0b0b";
        document.getElementById("an_staff").style.color = "#0b0b0b";
        document.getElementById(ele_id).style.color = "#01aaed";
        document.getElementById('right_role_li').style.display = 'none'
        document.getElementById('department_list').style.display = 'inline-block'
        deltr1();
        document.getElementById("img-display1").style.display = "inline-block";
        document.getElementById("department_list").innerHTML = "";
        var branch_list = window.branch_list;
        var department_list = document.getElementById("department_list");
        department_list.innerHTML = "";
        var ul_tag = document.createElement("ul");ul_tag.style.fontSize = "0";ul_tag.style.margin = "0";ul_tag.style.padding = "0";
        for (var i = 0; i < branch_list.length; i++) {
            var li_tag = document.createElement("li");
            li_tag.style.fontSize = "14px";li_tag.style.margin = "0";li_tag.style.padding = "0";li_tag.innerHTML = branch_list[i];li_tag.setAttribute("id", branch_list[i]);li_tag.setAttribute("onclick", "choice_peopel('" + branch_list[i] + "', " + "this.id" + ")");li_tag.className = "li-class";
            ul_tag.appendChild(li_tag);department_list.appendChild(ul_tag);
        }
    }
}

function search_data(ele_id) {
    var searchData = document.getElementById("search_data").value;
    let personnel_list = window.personnel_list;
    let emp_info_dict = window.emp_info_dict;
    for (var i in personnel_list) {
        if (personnel_list[i].indexOf(searchData) !== -1) {
            var real_name = searchData;
            var job_number = "";
            for (var t = 0; t < emp_info_dict[i].length; t++) {
                if (emp_info_dict[i][t]["real_name"] === searchData) {
                    real_name = emp_info_dict[i][t]["real_name"];
                    job_number = emp_info_dict[i][t]["job_number"];
                }
            }
            deltr1();
            var department_list = document.getElementById("department_list");
            department_list.innerHTML = "";
            var ul_tag = document.createElement("ul");ul_tag.style.fontSize = "0";ul_tag.style.margin = "0";ul_tag.style.padding = "0";
            var li_tag = document.createElement("li");li_tag.style.fontSize = "14px";li_tag.style.margin = "0";li_tag.style.padding = "0";li_tag.style.background = "#A9A9A9";li_tag.innerHTML = "<p style='margin-left: 20%;'>" + i + "</p>";li_tag.setAttribute("onclick", "choice_peopel('" + i + "')");li_tag.setAttribute("id", i);li_tag.className = "li-class";
            ul_tag.appendChild(li_tag);
            department_list.appendChild(ul_tag);
            var t_table = document.getElementById("t_table2");
            var tr = document.createElement("tr");var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");
            td.innerHTML = "<input id='" + real_name + "(" + job_number + ")' class='check_box' type=\"checkbox\" onclick='choice_consignor(this.id, \"" + ele_id + "\"" + ", \"" + i + "\")'>";
            td.style.textAlign = "center";td1.innerHTML = 1;td1.style.textAlign = "center";
            td2.innerHTML = real_name;td2.title = real_name;td2.style.textAlign = "center";
            td3.style.textAlign = "center";td3.innerHTML = job_number;td3.title = job_number;
            tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);
            t_table.appendChild(tr);document.getElementById("img-display1").style.display = "none";
        }
    }
}

function close_models() {
    document.getElementById("new_models").style.display = "none";
}

function close_models2() {
    document.getElementById("new_models2").style.display = "none";
}

function remove_time_adress(obj) {
    var trNode = $(obj).parent().parent();
    trNode.remove();
}

function create_multiseriate() {
    var table_label = document.getElementById("table_detail");
    var tr = document.createElement('tr');tr.style.width='100%';tr.style.position='relative';
    var td1 = document.createElement('td');td1.className='label_title';td1.contentEditable='true';td1.style.borderTop='none';
    var td2 = document.createElement('td');td2.className='label_value';td2.style.borderTop='none';
    var td3 = document.createElement('td');td3.className='label_title';td3.contentEditable='true';td3.style.borderTop='none';
    var td4 = document.createElement('td');td4.className='label_value';td4.style.borderTop='none';
    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;margin-left: 10px;margin-top: 7.5px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.className='remove_img';
    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(span);table_label.appendChild(tr);
}

function create_single() {
    var table_label = document.getElementById("table_detail");
    var tr = document.createElement('tr');tr.style.width='100%';tr.style.position='relative';
    var td1 = document.createElement('td');td1.className='label_title';td1.contentEditable='true';td1.style.borderTop='none';
    var td2 = document.createElement('td');td2.className='label_value';td2.style.width='85%';td2.colSpan='3';td2.style.borderTop='none';
    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;margin-left: 10px;margin-top: 7.5px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.className='remove_img';
    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(span);table_label.appendChild(tr);
}

function create_appendix() {
    var table_label = document.getElementById("create_table");
    var party_main = document.createElement('table');party_main.style.width='100%';party_main.id='party_main';party_main.style.position='relative';
    var tr1 = document.createElement('tr');tr1.style.width='100%';tr1.style.background='#dfdfdf';tr1.style.color='#1E90FF';tr1.style.paddingLeft='1%';tr1.style.border='#cccccc solid 1px';tr1.style.borderTop='none';tr1.style.borderBottom='none';tr1.style.paddingRight='1%';
    var td1 = document.createElement('td');td1.style.paddingRight='1%';td1.style.paddingTop='2.5px';td1.colSpan='6';
    var p_tag = document.createElement('p');p_tag.style.paddingRight='1%';p_tag.style.display='inline-block';p_tag.style.verticalAlign='top';p_tag.style.marginTop='5px';p_tag.style.color='4F4F4F';p_tag.innerText='上传附件';
    var a_tag = document.createElement('a');a_tag.href='javascript:;';a_tag.className='file';a_tag.style.verticalAlign='top';a_tag.style.float='right';a_tag.style.marginBottom='2.5px';
    a_tag.innerHTML = `上传文件 <input type="file" name="party_main_body" id="party_main_body" onchange="upload_accessory('file1', 'party_main', 'party_main_body')">`

    var tr2 = document.createElement('tr');tr2.style.width='100%';
    var td2 = document.createElement('td');td2.style.width='5%';td2.style.border='#cccccc solid 1px';td2.style.textAlign='center';td2.innerText='序号';
    var td3 = document.createElement('td');td3.style.width='20%';td3.style.border='#cccccc solid 1px';td3.style.borderLeft='none';td3.style.textAlign='center';td3.innerText='文件名称';
    var td4 = document.createElement('td');td4.style.width='20%';td4.style.border='#cccccc solid 1px';td4.style.borderLeft='none';td4.style.textAlign='center';td4.innerText='上传时间';
    var td5 = document.createElement('td');td5.style.width='20%';td5.style.border='#cccccc solid 1px';td5.style.borderLeft='none';td5.style.textAlign='center';td5.innerText='上传人员';
    var td6 = document.createElement('td');td6.style.width='20%';td6.style.border='#cccccc solid 1px';td6.style.borderLeft='none';td6.style.textAlign='center';td6.innerText='文件大小';
    var td7 = document.createElement('td');td7.style.width='15%';td7.style.border='#cccccc solid 1px';td7.style.borderLeft='none';td7.style.textAlign='center';td7.innerText='操作';
    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.style.right="-30px";span.style.top="25px";span.className='remove_img';
    td1.appendChild(p_tag);td1.appendChild(a_tag);tr1.appendChild(td1);party_main.appendChild(tr1);
    tr2.appendChild(td2);tr2.appendChild(td3);tr2.appendChild(td4);tr2.appendChild(td5);tr2.appendChild(td6);tr2.appendChild(td7);party_main.appendChild(tr2);party_main.appendChild(span);table_label.appendChild(party_main);
}

function create_Division() {
    var table_label = document.getElementById("table_detail");
    var tr = document.createElement('tr');tr.style.width='100%';tr.style.position='relative';
    var td2 = document.createElement('td');td2.className='label_value';td2.style.width='100%';td2.colSpan='4';td2.style.background='#E8E8E8';td2.style.paddingLeft='1%';td2.contentEditable='true';td2.style.borderTop='none';
    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;margin-left: 10px;margin-top: 7.5px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.className='remove_img';
    tr.appendChild(td2);tr.appendChild(span);table_label.appendChild(tr);
}

function create_essential() {
    var table_label = document.getElementById("table_essential");
    var table = document.createElement('table');table.style.width='100%';table.style.position='relative';
    var tr = document.createElement('tr');tr.style.width='100%';
    var td1 = document.createElement('td');td1.className='label_value';td1.style.width='100%';td1.colSpan='4';td1.style.background='#E8E8E8';td1.style.paddingLeft='1%';td1.style.borderTop='none';td1.innerText='基本信息';
    var tr1 = document.createElement('tr');tr1.style.width='100%';
    var td2 = document.createElement('td');td2.className='label_title';td2.contentEditable='true';td2.innerText='姓名';
    var td3 = document.createElement('td');td3.className='label_value';td3.innerHTML='{{ real_name }}';
    var td4 = document.createElement('td');td4.className='label_title';td4.contentEditable='true';td4.innerText='所属科室';
    var td5 = document.createElement('td');td5.className='label_value';td5.innerHTML='{{ department }}';

    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.style.right="-30px";span.style.top="25px";span.className='remove_img';

    tr.appendChild(td1);tr1.appendChild(td2);tr1.appendChild(td3);tr1.appendChild(td4);tr1.appendChild(td5);
    table.appendChild(tr);table.appendChild(tr1);table.appendChild(span);table_label.appendChild(table);
}

function department_selection() {
    var table_label = document.getElementById("table_detail");
    var tr = document.createElement('tr');tr.style.width='100%';tr.style.position='relative';
    var td1 = document.createElement('td');td1.className='label_title';td1.contentEditable='true';td1.style.borderTop='none';
    var td2 = document.createElement('td');td2.className='label_value';td2.style.width='85%';td2.colSpan='3';td2.style.borderTop='none';
    td2.setAttribute("onclick", 'company_line()');td2.id='Department';
    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;margin-left: 10px;margin-top: 7.5px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.className='remove_img';
    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(span);table_label.appendChild(tr);
 }

function company_line(){
    document.getElementById("new_models2").style.display='table-cell';
 }

function choose_department() {
    var cleck_box_list = document.getElementsByClassName("check_box3");
    var xuanzhong = ""
    for (var t=0; t<cleck_box_list.length; t++){
        if (cleck_box_list[t].checked){
            xuanzhong = xuanzhong+cleck_box_list[t].id+", "
        }
    }
    document.getElementById("Department").innerText=xuanzhong.slice(0, -2);
    document.getElementById("new_models2").style.display = "none";
}

function personnel_selection() {
    var table_label = document.getElementById("table_detail");
    var tr = document.createElement('tr');tr.style.width='100%';tr.style.position='relative';
    var td1 = document.createElement('td');td1.className='label_title';td1.contentEditable='true';td1.style.borderTop='none';
    var td2 = document.createElement('td');td2.className='label_value';td2.style.width='85%';td2.colSpan='3';td2.style.borderTop='none';
    td2.setAttribute("onclick", 'fill_val1()');td2.id='SelectPersonnel';
    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;margin-left: 10px;margin-top: 7.5px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.className='remove_img';
    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(span);table_label.appendChild(tr);
}

function MultiColumnTimeSelector() {
    var table_label = document.getElementById("table_detail");
    var label_count = document.getElementsByClassName('label_value label_time').length;
    var tr = document.createElement('tr');tr.style.width='100%';tr.style.position='relative';
    var td1 = document.createElement('td');td1.className='label_title';td1.contentEditable='true';td1.style.borderTop='none';td1.innerText='开始时间';
    var td2 = document.createElement('td');td2.className='label_value label_time';td2.style.borderTop='none';td2.id='time_'+String(label_count+1);
    var td3 = document.createElement('td');td3.className='label_title';td3.contentEditable='true';td3.style.borderTop='none';td3.innerText='结束时间';
    var td4 = document.createElement('td');td4.className='label_value label_time';td4.style.borderTop='none';td4.id='time_'+String(label_count+2);
    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;margin-left: 10px;margin-top: 7.5px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.className='remove_img';
    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(span);table_label.appendChild(tr);

    lay('#version').html('-v' + laydate.v);

    //执行一个laydate实例
    laydate.render({
        elem: '#time_'+String(label_count+1), //指定元素
        type: 'date',
        format: 'yyyy-MM-dd'
    });
    laydate.render({
        elem: '#time_'+String(label_count+2), //指定元素
        type: 'date',
        format: 'yyyy-MM-dd'
    });
}

function SingleColumnTimeSelector() {
    var table_label = document.getElementById("table_detail");
    var label_count = document.getElementsByClassName('label_value label_time').length;
    var tr = document.createElement('tr');tr.style.width='100%';tr.style.position='relative';
    var td1 = document.createElement('td');td1.className='label_title';td1.contentEditable='true';td1.style.borderTop='none';td1.innerText='开始时间';
    var td2 = document.createElement('td');td2.className='label_value label_time';td2.style.borderTop='none';td2.colSpan='3';td2.style.width='85%';td2.id='time_'+String(label_count+1);
    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;margin-left: 10px;margin-top: 7.5px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.className='remove_img';
    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(span);table_label.appendChild(tr);

    lay('#version').html('-v' + laydate.v);

    //执行一个laydate实例
    laydate.render({
        elem: '#time_'+String(label_count+1), //指定元素
        type: 'date',
        format: 'yyyy-MM-dd'
    });
}

function CreateMultilineText() {
    var table_label = document.getElementById("table_detail");
    var tr = document.createElement('tr');tr.style.width='100%';tr.style.position='relative';
    var td1 = document.createElement('td');td1.className='label_title';td1.contentEditable='true';td1.style.borderTop='none';
    var td2 = document.createElement('td');td2.className='label_value wrap-td';td2.style.borderTop='none';td2.colSpan='3';td2.style.width='85%';td2.contentEditable='true';td2.style.paddingLeft='1%';
    var span = document.createElement('div');span.innerHTML='<img onclick="remove_time_adress(this)" src="../../static/jqueryjsPlumb/images/remove.png" style="width: 20px;height: 20px;margin-left: 10px;margin-top: 7.5px;cursor: pointer;">';span.style.position='absolute';span.style.zIndex='100';
    span.className='remove_img';
    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(span);table_label.appendChild(tr);
}

var box = document.getElementById('box');
var isDown = false;
var mouse = {};
box.onmousedown = (e) => {
    isDown = true;
    isDown_1 = false;
    //保存初始位置
    mouse = {
        startX: e.clientX,
        startY: e.clientY,
        offsetLeft: box.offsetLeft,
        offsetTop: box.offsetTop,
    }
};

box.onmousemove = (e) => {
    if (!isDown) {
        return
    }
    //计算偏移位置
    var offsetLeft = mouse.offsetLeft + e.clientX - mouse.startX;
    var offsetTop = mouse.offsetTop + e.clientY - mouse.startY;

    //设置偏移距离的范围[0,window.innerWidth - 400]
    offsetLeft = Math.max(0, Math.min(offsetLeft, window.innerWidth - 400));
    offsetTop = Math.max(0, Math.min(offsetTop, window.innerHeight - 400));

    box.style.left = offsetLeft + 'px';
    box.style.top = offsetTop + 'px';

};
//当鼠标滑的太快时，容易移出box，所以在window上监听此事件
window.onmouseup = () => {
    isDown = false;
    box.style.cursor = 'default';
    mouse = null;
};

let title2 = document.querySelector("#title2");
let addForm2 = document.querySelector("#box2");
if (title2) {
    title2.addEventListener("mousedown", function (e) {
        let x = e.pageX - addForm2.offsetLeft;
        let y = e.pageY - addForm2.offsetTop;


        document.addEventListener("mousemove", move);
        function move(e) {
            addForm2.style.left = e.pageX - x + 'px';
            addForm2.style.top = e.pageY - y + 'px';
        }

        document.addEventListener("mouseup", function (e) {
            document.removeEventListener("mousemove", move);
        })
    })
}


let title3 = document.querySelector("#title3");
let addForm3 = document.querySelector("#addForm");
if (title3) {
    title3.addEventListener("mousedown", function (e) {
        let x = e.pageX - addForm3.offsetLeft;
        let y = e.pageY - addForm3.offsetTop;


        document.addEventListener("mousemove", move);
        function move(e) {
            addForm3.style.left = e.pageX - x + 'px';
            addForm3.style.top = e.pageY - y + 'px';
        }

        document.addEventListener("mouseup", function (e) {
            document.removeEventListener("mousemove", move);
        })
    })
}